Topic: Operator overloading
Points: 25
Instructor: Dana Steil
Modify your String Class to
overload the following operators according the given specifications.
|
Return |
Parameter(s) |
Description |
const |
|
= |
const String& |
String,char* int
or char |
Sets the member variable to the parameter passed
in. Returns what’s at this. |
N |
|
+ |
String |
String, char* int
or char |
Returns a new object of type String that contains
the contents of “this” String with the contents of the parameter
concatenated. |
Y |
|
+= |
void |
String, char* int
or char |
Concatenates the parameter to its own string. |
N |
|
* |
String |
int
n |
Returns a String that is the current string
repeated n times. |
Y |
|
*= |
void |
int
n |
Changes the current String to be its current
contents repeated n times. |
|
|
== |
bool |
String, char* int
or char |
Returns true if the contents of the parameter
match exactly the contents of its own string.
Returns false otherwise. |
Y |
|
< |
bool |
String, char* int
or char |
Returns true if the contents of its own string is lexicographically
less than the contents of the parameter. Returns false otherwise. |
Y |
|
> |
bool |
String, char* int
or char |
Returns true if the contents of its own string is lexicographically
greater than the contents of the parameter. Returns false otherwise. |
Y |
|
<= |
bool |
String, char* int
or char |
Returns true if the contents of its own string is lexicographically
less than or equal to the contents of the parameter. Returns false otherwise. |
Y |
|
>= |
bool |
String, char* int
or char |
Returns true if the contents of its own string is lexicographically
greater than or equal to the contents of the parameter. Returns false otherwise. |
Y |
|
!= |
bool |
String, char* int
or char |
Returns false if the contents of the parameter
match exactly the contents of its own string.
Returns true otherwise. |
Y |
|
>> |
istream
& |
istream
& and String & |
Friend function that sets the member variables of
the String object passed in. |
NA |
|
<< |
ostream
& |
ostream
& and String & |
Friend function that prints the member variables
of the String object passed in. |
NA |
|
[] |
const char& |
int |
Returns a constant reference to the character in
the array at the given position. |
Y |
|
[] |
char& |
int |
Returns a reference to the character in the array
at the given position. |
N |
|
() |
int |
None |
Returns the length of the string. |
Y |
|
Add a public static Boolean
data member isCaseSensitive. Make all comparisons case sensitive when it is
true. This variable should be
initialized to false.
Notes:
1.
You should add as
many private helper functions as is appropriate.
2.
Let the
conversion constructors work for you.